﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TracedReality.RayTracing;
using QiHe.Yaml.Grammar;

namespace TracedReality.Primitive
{
    /// <summary>
    /// A specific instance of Box where each side is the same length.
    /// </summary>
    public class Cube : Box
    {
        /// <summary>
        /// Create a Cube with the given corner, size, and Material.
        /// </summary>
        /// <param name="c">Corner.</param>
        /// <param name="s">Size.</param>
        /// <param name="m">Material.</param>
        public Cube(Vector c, double s, ref Material m) : base(c, new Vector(s), ref m)
        { }

        public static new Cube Parse(MappingEntry entry)
        {
            if (entry == null) { throw new ArgumentNullException("entry"); }

            Mapping map = (Mapping)entry.Value;
            Material material = Material.Parse(map.Find("material"));
            MappingEntry found = map.Find("corner");
            if (found == null) { throw new ArgumentException("No corner entry"); }
            Vector corner = Vector.FromSequence((Sequence)found.Value);
            found = map.Find("size");
            if (found == null) { throw new ArgumentException("No size entry"); }
            double size = double.Parse(found.Value.ToString());

            return new Cube(corner, size, ref material);
        }

        /// <summary>
        /// Get a string representation of this Cube.
        /// </summary>
        /// <returns>A string representing this Cube.</returns>
        public override string ToString()
        {
            return "Cube: { corner: " + corner + ", size: " + size.x + ", material: " + material + " }";
        }
    }
}
